package hu.crs.demobank.function.transfer;

import hu.crs.demobank.backend.DbOperations;
import hu.crs.demobank.backend.dto.TransferDTO;
import hu.crs.demobank.bean.BeanManager;
import hu.crs.demobank.user.User;

import java.util.Date;

public class Transfer {
	Integer id;
	String toAccount1 = "00000000";
	String toAccount2;
	String toAccount3;
	Integer amount = 0;
	String comment;

	TransferDTO transferDTO;

	public String confirm() {
		return "success";
	}

	public String result() {
		id = DbOperations.persistTransfer(buildResult());
		return "success";
	}

	public TransferDTO buildResult() {
		User user = (User) BeanManager.find("user");
		String fromAccount = user.getAccount();
		String toAccount = toAccount1 + toAccount2 + toAccount3;

		transferDTO = new TransferDTO(fromAccount, toAccount, amount, comment,
				new Date());

		return transferDTO;

	}

	public String getToAccount1() {
		return toAccount1;
	}

	public void setToAccount1(String toAccount1) {
		this.toAccount1 = toAccount1;
	}

	public String getToAccount2() {
		return toAccount2;
	}

	public void setToAccount2(String toAccount2) {
		this.toAccount2 = toAccount2;
	}

	public String getToAccount3() {
		return toAccount3;
	}

	public void setToAccount3(String toAccount3) {
		this.toAccount3 = toAccount3;
	}

	public Integer getAmount() {
		return amount;
	}

	public void setAmount(Integer amount) {
		this.amount = amount;
	}

	public String getComment() {
		return comment;
	}

	public void setComment(String comment) {
		this.comment = comment;
	}

	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}
}
